package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC367 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean isPerfectSquare(int num) {
            int left = 1, right = num, mid = 0;
            while (left <= right) {
                mid = left + (right - left) / 2;
                long multi = ((long) mid) * mid;
                if (multi == num) return true;
                if (multi > num) right = mid - 1;//too big or overflow
                else left = mid + 1;
            }

            return false;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.isPerfectSquare(2147395600));
    }

    public static void main(String[] args) throws Exception {
        LC367 an = new LC367();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
